<?php defined('BASEPATH') OR exit('No direct script access allowed');

// Code here is run before admin controllers
class Admin_Controller extends MY_Controller
{
	function Admin_Controller()
	{
		parent::__construct();

	    // Show error and exit if the user does not have sufficient permissions
	    if( ! self::_check_access() )
	    {
//	    	show_error($this->lang->line('cp_access_denied'));
//		    exit;
			redirect('admin/login');
	    }
	    // Template configuration
		$this->template
			->set_layout('default', 'admin')
			->enable_parser(FALSE);
	}

	private function _check_access()
	{
		// These pages get past permission checks
	    $ignored_pages = array('admin/login', 'admin/logout');

	    // Check if the current page is to be ignored
	    $current_page = $this->uri->segment(1, '') . '/' . $this->uri->segment(2, 'index');

		$is_login = $this->session->userdata('is_login');
//		p($is_login);
	    // Dont need to log in, this is an open page
		if(in_array($current_page, $ignored_pages))
		{
			return TRUE;
		}
		else if (TRUE == $is_login)
		{
			return TRUE;
		}
		return FALSE;
	}
}